﻿using JsonFx.Json;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class CashData
{
	private static CashData instance;

	public CashUsageData[] cashUsage;
	public CashChargeData[] cash;

	private static CashData Inst { get { Init(); return instance; } }

	public static CashUsageData[] CashUsage { get { return Inst.cashUsage; } }
	public static CashChargeData[] Cash { get { return Inst.cash; } }

	public static void Init()
	{
		if (instance == null)
		{
            string data = null;
            using (System.IO.StreamReader r = System.IO.File.OpenText(Application.persistentDataPath + "/cash.json"))
            {
                data = r.ReadToEnd();
            }
            instance = JsonReader.Deserialize<CashData>(data);
            Debug.Log("cashdata init");
		}
	}

	public static List<CashUsageData> GetCashUsageData(CashUsageData.UsageType type)
	{
		return CashUsage.Where(d => d.usageType == type).ToList();
	}
}

public class CashUsageData
{
	public enum UsageType : byte
	{
		ORDER,
		EMPLOY_GOLD_REFRESH,
		HEART_CHARGE,
		POLICY_COOLTIME_REMOVE,
	}

	public UsageType usageType;
	public byte type { get { return (byte)usageType; } set { usageType = (UsageType)value; } }
	public int itemID;
	public short amount;
	public int cost_org;
	public int cost_kr;
	public int cost_cn;
	public int cost_us;

	public int GetCost()
	{
		return cost_org;
	}
}

public class CashChargeData
{
	public int cash;

	public string[] productid = new string[3];
	public string[] currency = new string[3];
	public float[] cost = new float[3];

	public string productid1 { get { return productid[0]; } set { productid[0] = value; } }
	public string currency1 { get { return currency[0]; } set { currency[0] = value; } }
	public float cost1 { get { return cost[0]; } set { cost[0] = value; } }

	public string productid2 { get { return productid[1]; } set { productid[1] = value; } }
	public string currency2 { get { return currency[1]; } set { currency[1] = value; } }
	public float cost2 { get { return cost[1]; } set { cost[1] = value; } }

	//public string productid3 { get { return productid[2]; } set { productid[2] = value; } }
	//public string currency3 { get { return currency[2]; } set { currency[2] = value; } }
	//public float cost3 { get { return cost[2]; } set { cost[2] = value; } }

	public string GetProductId()
	{
		return productid[0];
	}

	public string GetCurrency()
	{
		return currency[0];
	}

	public float GetCost()
	{
		return cost[0];
	}
}
